﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EngineAdmin;
using GameEngine;

namespace DaphneProfiBase
{
    /// <summary>
    /// Move Helper Class
    /// </summary>
    public static class MoveHelper
    {
        /// <summary>
        /// The current gameboard model conversion
        /// </summary>
        public static eFigure[,] ConvertCheckersBoard(GameBoard gameboard)
        {
            eFigure[,] board = new eFigure[gameboard.Size, gameboard.Size];

            for (int row = 0; row < gameboard.Size; row++)
            {
                for (int col = 0; col < gameboard.Size; col++)
                {
                    enumFigureType figure = gameboard.GetField(row, col);
                    eFigure fig = eFigure.None;
                    switch (figure)
                    {
                        case enumFigureType.WhiteMan:
                            fig = eFigure.WhiteMan;
                            break;
                        case enumFigureType.WhiteKing:
                            fig = eFigure.WhiteKing;
                            break;
                        case enumFigureType.BlackMan:
                            fig = eFigure.BlackMan;
                            break;
                        case enumFigureType.BlackKing:
                            fig = eFigure.BlackKing;
                            break;
                    }

                    board[row, col] = fig;
                }
            }

            return board;
        }


        /// <summary>
        /// Converts the move history
        /// </summary>
        public static EngineAdmin.BitBoard[] ConvertMoveHistory(GameManager gameManager)
        {
            List<EngineAdmin.BitBoard> list = new List<EngineAdmin.BitBoard>();

            List<Move> lstGameHistory = new List<Move>();
            gameManager.MoveHistory.GetMoveList(lstGameHistory);

            EngineAdmin.BitBoard bb;
            foreach (var move in lstGameHistory)
            {
                bb = new EngineAdmin.BitBoard();
                bb.WM = (ulong)move.bitOriginalPosition.bitWM;
                bb.WK = (ulong)move.bitOriginalPosition.bitWQ;
                bb.BM = (ulong)move.bitOriginalPosition.bitBM;
                bb.BK = (ulong)move.bitOriginalPosition.bitBQ;

                list.Add(bb);
            }

            GameEngine.BitBoard bitOrig = gameManager.GameBoard.PackGameBoard();
            bb = new EngineAdmin.BitBoard();
            bb.WM = (ulong)bitOrig.bitWM;
            bb.WK = (ulong)bitOrig.bitWQ;
            bb.BM = (ulong)bitOrig.bitBM;
            bb.BK = (ulong)bitOrig.bitBQ;

            list.Add(bb);

            return list.ToArray();
        }
    }
}
